package javasec.seed.seeds;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.SQLIntegrityConstraintViolationException;
import java.sql.Timestamp;

import java.lang.reflect.Method;
import java.lang.Thread;

import java.util.Properties;

import javasec.seed.Exposed;
import javasec.seed.Seed;
import javasec.seed.SeedServer;

//import jpcap.*;
//import jpcap.packet.Packet;
//import jpcap.packet.DatalinkPacket;
//import jpcap.packet.EthernetPacket;
//import jpcap.packet.IPPacket;
//import jpcap.packet.UDPPacket;
//import java.io.Serializable;


public class DNSMonitor extends Seed
{
	/*
	private Connection conn=SeedServer.conn;
	private boolean monitoring=false;
	*/
	public DNSMonitor() throws RemoteException
	{
		/*
		System.out.println("DNSMonitor: starting up");
		try
		{
			Statement statement = conn.createStatement();

			statement.execute(
				"create table BLUESEED_DNS_QUERY("+
					"DOMAIN varchar(40) not null unique,"+
					"QUERY_ID integer not null primary key generated always as identity,"+
					"MAC_PARENT varchar(40) not null,"+
					"MAC_PARENT_ID integer not null,"+
					"NOTE varchar(100) not null,"+ // just useful to have around
					"TIMESTAMP timestamp)");

			System.out.println("DNSMonitor: created tables");
		}
		catch(SQLException sqle)
		{
			System.out.println("DNSMonitor: tables already in place");
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		*/
	}

	public void addDNSQuery(String domain, String mac)
	{
		/*
		System.out.println(mac+" is looking at "+domain);

		Statement query = null;
		PreparedStatement preparedQuery = null;
		ResultSet resultSet = null;
		int macID;
		
		// find which mac address did the query (macID)
		try
		{
			preparedQuery=conn.prepareStatement("select * from BLUESEED_MAC_NODES where MAC=?");
			preparedQuery.setString(1,mac);
			resultSet=preparedQuery.executeQuery();

			if(resultSet.next())
			{
				macID=resultSet.getInt(2);
			}
			else
			{
				// I don't know who that did this query..
				return;
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return;
		}

		// insert the row
		try
		{
			preparedQuery=conn.prepareStatement(
				"insert into BLUESEED_DNS_QUERY"+
				"(DOMAIN,MAC_PARENT,MAC_PARENT_ID,TIMESTAMP) values (?,?,?,?)");

			preparedQuery.setString(1,domain);
			preparedQuery.setString(2,mac);
			preparedQuery.setInt(3,macID);
			preparedQuery.setTimestamp(4,new Timestamp(System.currentTimeMillis()));
			preparedQuery.executeUpdate();
			conn.commit();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}

		return;
		*/
	}

}
